cmake_minimum_required(VERSION 3.10.0)
project(orbclip VERSION 0.1)

if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
    set(CMAKE_BUILD_TYPE "Release")
    # set(CMAKE_BUILD_TYPE "Debug")
endif()

set(CMAKE_DEBUG_POSTFIX _d)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/modules)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

message("BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
if (“${CMAKE_BUILD_TYPE}” MATCHES "Debug")
    add_definitions(-DNDEBUG)
endif()

aux_source_directory(src SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})

##=============== Library : boost
SET(BOOST_USE_MULTITHREADED ON)
find_package(Boost 1.70 COMPONENTS system thread filesystem chrono date_time REQUIRED)
if (Boost_FOUND)
	message("boost version   : ${Boost_VERSION}")
	message("boost include   : ${Boost_INCLUDE_DIRS}")
	message("boost libraries : ${Boost_LIBRARIES}")
    include_directories(${Boost_INCLUDE_DIRS})
    target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
else()
    message(FATAL_ERROR " : not found boost SDKs")
endif()

##=============== Library : cfitsio
find_package(cfitsio REQUIRED)
if (CFITSIO_INC AND CFITSIO_LIB)
    message("include : ${CFITSIO_INC}")
    message("link : ${CFITSIO_LIB}")
   include_directories(${CFITSIO_INC})
    target_link_libraries(${PROJECT_NAME} ${CFITSIO_LIB})
else()
    message(FATAL_ERROR " : not found [cfitsio] SDKs")
endif ()

##=============== Library : stdc++, for Linux
message(STATUS "operation system is ${CMAKE_SYSTEM}")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
	add_definitions(-DLINUX)
	target_link_libraries(${PROJECT_NAME}
        rt
        pthread)
endif ()
target_link_libraries(${PROJECT_NAME} m)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

INSTALL(TARGETS ${PROJECT_NAME} DESTINATION "/usr/local/bin/")
